//配置axios全局路径
axios.defaults.baseURL='http://127.0.0.1:10030/services/';
Vue.prototype.$http = axios

//解析url参数函数
function parseParamObj(url) {
    let paramsStr = url.substring(url.indexOf("?")+1); //typeId=27
    let paramsArray = paramsStr.split("&"); //typeId=27 xxx=xxx
    let paramObj = {};
    $.each(paramsArray,function(index,param){
        let parmName = param.split("=")[0];
        let parmValue = param.split("=")[1];
        paramObj[parmName] = parmValue;//动态属性
    })
    return paramObj;
}

/*let excludeUrls = ['/index.html','/about.html'];//放行地址
let url = location.href;//获取当前url
let isRun = false; //是否放行 默认false-拦截
if(url=="http://localhost:8081/"||url=="http://127.0.0.1:8081/"){//特殊地址
    isRun = true;
}else {
    for (let i=0;i<excludeUrls.length;i++){//遍历白名单 判断url是否在白名单内
        if (url.indexOf(excludeUrls[i])!=-1){
            isRun = true;
            break;
        }
    }
}


//拦截
if (!isRun){
    let loginUser = localStorage.getItem("loginUser")
    if (!loginUser)
        alert("请登录后再访问")
}*/

/*axios拦截 所有请求都携带token*/
/*axios.interceptors.request.use(config=>{
    let token =  JSON.parse(localStorage.getItem("token"))//localStorage中存的是json字符串 需要转化成json对象
    console.log("token:"+token)
    if(token){
        config.headers['token']=token;
    }
    return config;
},error => {
    Promise.reject(error);
})*/
//使用axios后置拦截器，处理没有登录请求
//==============axios后台拦截器实现后端已经退出登录的跳转登录页面======================//
/*axios.interceptors.response.use(config=>{
    let data = config.data;
    if(!data.success && "noLogin"===data.message)
    {
        //没有登陆就跳转到登陆界面
        localStorage.removeItem('loginUser');
        localStorage.removeItem('token');
        alert("请先登陆后再操作")
    }
    return config;
},error => {
    Promise.reject(error)
})*/
//==============axios后台拦截器实现后端已经退出登录的跳转登录页面======================//